<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html">

    <body>
        <ui:composition template="../templates/default3.xhtml">
            <ui:define name="content">
                <h:form binding="#{creditManagerBean.loadAddCredit}">
                    <p:panel header="Customer Information" id="customerInformationPanel">
                        <table width="100%" border="0">
                            <tr>
                                <td width="200px">
                                    Company:
                                </td>
                                <td>
                                    <h:outputText id="company" value="#{creditManagerBean.selectedCustomer.company}" />
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">
                                    Description:
                                </td>
                                <td>
                                    <h:outputText id="description" value="#{creditManagerBean.selectedCustomer.description}" />
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">
                                    Annual Revenue:
                                </td>
                                <td>
                                    <h:outputText id="revenue" value="#{creditManagerBean.selectedCustomer.revenue}">
                                        <f:convertNumber type="currency"/>
                                    </h:outputText>
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">
                                    Number of Employees:
                                </td>
                                <td>
                                    <h:outputText id="numEmployee" value="#{creditManagerBean.selectedCustomer.numEmployee}" />
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">
                                    Contact Person
                                </td>
                                <td>
                                    <h:outputText id="contactPerson" value="#{creditManagerBean.selectedCustomer.firstName}, 
                                                  #{creditManagerBean.selectedCustomer.lastName}" />
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">
                                    Designation:
                                </td>
                                <td>
                                    <h:outputText id="title" value="#{creditManagerBean.selectedCustomer.title}" />
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">
                                    Contact Number:
                                </td>
                                <td>
                                    <h:outputText id="phone" value="#{creditManagerBean.selectedCustomer.phone}" />
                                </td>
                            </tr>
                        </table>
                    </p:panel>
                    <p:panel header="Credit Information" id="creditInformationPanel">
                        <font class="fieldNote">* - Mandatory Field<br/></font>
                        <p:messages />

                        <table width="100%" border="0">

                            <tr>
                                <td colspan="2">
                                    Total Payments Made:
                                </td>
                                <td class="creditAlign">
                                    <h:outputText id="totalPayments" value="#{creditManagerBean.totalPayments}" 
                                                  title="Total number of payments made by customer."
                                                  styleClass="creditField">
                                        <f:convertNumber type="number"/>  
                                    </h:outputText>
                                </td>
                                <td width="370"></td>
                            </tr>
                            <tr>
                                <td width="100" rowspan="4" align="center"><b>Days Late for Payment</b></td>
                                <td width="100">Less Than 30:</td>
                                <td class="creditAlign">
                                    <h:outputText id="paymentsPaidLessThan30" value="#{creditManagerBean.paymentsPaidLessThan30}"
                                                  title="Total number of payments made by customer in less than 30 days."
                                                  styleClass="creditField"> 
                                    </h:outputText>
                                </td>
                                <td></td>
                            </tr>
                            <tr>
                                <td>30 to 59:</td>
                                <td class="creditAlign">
                                    <h:outputText id="paymentsPaidLate30to59" value="#{creditManagerBean.paymentsPaidLate30to59}"
                                                  title="Total number of payments made by customer within 30 to 59 days."
                                                  styleClass="creditField">
                                    </h:outputText>
                                </td>
                                <td></td>
                            </tr>
                            <tr>
                                <td>60 to 89:</td>
                                <td class="creditAlign">
                                    <h:outputText id="paymentsPaidLate60to89" value="#{creditManagerBean.paymentsPaidLate60to89}"
                                                  title="Total number of payments made by customer within 60 to 89 days."
                                                  styleClass="creditField">
                                    </h:outputText>
                                </td>
                                <td></td>
                            </tr>
                            <tr>
                                <td>Later Than 90:</td>
                                <td class="creditAlign">
                                    <h:outputText id="paymentsPaidLaterThan90" value="#{creditManagerBean.paymentsPaidLaterThan90}"
                                                  title="Total number of payments made by customer later than 90 days."
                                                  styleClass="creditField">
                                    </h:outputText>
                                </td>
                                <td></td>
                            </tr>
                            <tr>
                                <td colspan="3" align="right" class="assessScore">
                                    Payment Score: 
                                    <h:outputText id="paymentScore" value="#{creditManagerBean.paymentScore}"    
                                                  styleClass="calcField"
                                                  title="Payment score calculated from total loans taken up and total loans paid for.">
                                        <f:convertNumber minFractionDigits="2" />  
                                    </h:outputText>

                                </td>
                                <td>

                                </td>
                            </tr>
                            <tr><td>&nbsp;</td></tr>
                            <tr>
                                <td colspan="2">Total Amount Transacted:</td>
                                <td class="creditAlign">
                                    <h:outputText id="totalAmount" value="#{creditManagerBean.totalAmount}"
                                                  title="Total amount transacted with us."
                                                  styleClass="creditField"> 
                                    </h:outputText>
                                </td>
                                <td></td>
                            </tr>
                            <tr>
                                <td colspan="2">Accounts Payable:</td>
                                <td class="creditAlign">
                                    <h:outputText id="accountsPayable" value="#{creditManagerBean.accountsPayable}"
                                                  title="Total accounts payable."
                                                  styleClass="creditField">
                                    </h:outputText>
                                </td>
                                <td></td>
                            </tr>
                            <tr class="creditAlign">
                                <td colspan="3" align="right" class="assessScore">Outstanding Score: 
                                    <h:outputText id="outstandingScore" value="#{creditManagerBean.outstandingScore}"
                                                  title="Outstanding score is calculated from the total amount transacted with us and the total amount owed to us.">
                                        <f:convertNumber minFractionDigits="2"/>  
                                    </h:outputText>
                                </td>
                                <td></td>
                            </tr>
                            <tr><td>&nbsp;</td></tr>
                            <tr>
                                <td colspan="2">Years in Business:</td>
                                <td class="creditAlign">
                                    <p:inputText id="yearsInBusiness" value="#{creditManagerBean.yearsInBusiness}"
                                                 required="true" requiredMessage="Years in business cannot be empty."
                                                 title="Customer's years in business. Enter only whole numbers."
                                                 label="Years in Business" styleClass="creditField"> 
                                        <p:ajax event="keyup" update="paymentScore,outstandingScore,relationshipScore,creditScore" 
                                                process="creditInformationPanel"
                                                listener="#{creditManagerBean.compute}" /> 
                                    </p:inputText>
                                    <font class="fieldNote">*</font>
                                </td>
                                <td></td>
                            </tr>
                            <tr>
                                <td colspan="2">Years of Dealings:</td>
                                <td class="creditAlign">
                                    <p:inputText id="yearsOfDealings" value="#{creditManagerBean.yearsOfDealings}"
                                                 required="true" requiredMessage="Years of dealings cannot be empty."
                                                 title="Customer's years of dealings with us. Enter only whole numbers."
                                                 label="Years of Dealings" styleClass="creditField"> 
                                        <p:ajax event="keyup" update="paymentScore,outstandingScore,relationshipScore,creditScore"
                                                process="creditInformationPanel"
                                                listener="#{creditManagerBean.compute}" /> 
                                    </p:inputText>
                                    <font class="fieldNote">*</font>
                                </td>
                                <td></td>
                            </tr>
                            <tr>
                                <td colspan="3" align="right" class="assessScore">Relationship Score: 
                                    <h:outputText id="relationshipScore" value="#{creditManagerBean.relationshipScore}"
                                                  title="Relationship score is calculated from the customer's years of dealings with us and their years in business.">
                                        <f:convertNumber minFractionDigits="2" />  
                                    </h:outputText>
                                </td>
                                <td></td>
                            </tr>
                            <tr>
                                <td colspan="3" align="right" class="creditScore">Credit Score: 
                                    <h:outputText id="creditScore" value="#{creditManagerBean.creditScore}"
                                                  title="Credit score is the total score calculated from the payment score, outstanding score and relationship score.">
                                        <f:convertNumber minFractionDigits="2" />  
                                    </h:outputText>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">Credit Rank:</td>
                                <td>
                                    <table border="0">
                                        <tr>
                                            <td>
                                                <h:selectOneMenu id="selectOneCreditRank" value="#{creditManagerBean.creditRank}"
                                                                 title="Credit rank to be given to customer. Different rank will mean varying credit limits.">
                                                    <f:selectItem itemLabel="Select Credit Rank" itemValue="" />
                                                    <f:selectItem itemLabel="Bronze (0%)" itemValue="Bronze" />
                                                    <f:selectItem itemLabel="Silver (10% or $50,000)" itemValue="Silver" />
                                                    <f:selectItem itemLabel="Gold (10% or $100,000)" itemValue="Gold" />
                                                    <f:selectItem itemLabel="Platinum (20% or $150,000)" itemValue="Platinum" />
                                                    <f:selectItem itemLabel="Titanium (30% or $200,000)" itemValue="Titanium" />
                                                    <f:selectItem itemLabel="Blacklisted" itemValue="Blacklisted" />
                                                </h:selectOneMenu>
                                            </td>
                                            <td><font class="fieldNote">*</font></td>
                                        </tr>
                                    </table>
                                </td>
                                <td></td>
                            </tr>
                            <tr>
                                <td colspan="2">Remark:</td>
                                <td colspan="2">
                                    <p:inputTextarea id="remark" value="#{creditManagerBean.remark}"
                                                     title="Remarks for the credit."
                                                     style="width:210px;height:75px;"> 
                                    </p:inputTextarea>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="4" class="btn">
                                    <hr/><p:commandButton id="btnAddCredit" value="Save" 
                                                          actionListener="#{creditManagerBean.save}" 
                                                          ajax="true" update="creditInformationPanel" 
                                                          title="Add this credit for the customer."/>                                </td>
                            </tr>
                        </table>
                    </p:panel>
                </h:form>
            </ui:define>
        </ui:composition>
    </body>
</html>